`
https://leetcode.cn/problems/squares-of-a-sorted-array/
`

/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortedSquares = function (nums) {
  const res = new Array(nums.length)

  // 左右指针初始化为两端，使用合并倒序的两个数组逻辑即可
  let left = 0, right = nums.length - 1

  let p = nums.length - 1

  while (p >= 0) {
    if (Math.abs(nums[left]) > Math.abs(nums[right])) {
      res[p] = nums[left] * nums[left]
      left++
    } else {
      res[p] = nums[right] * nums[right]
      right--
    }
    p--
  }
  return res
};